<?php

/**
 * 短信接口，实现简单工厂模式样例
 */

namespace sms;

use sms\AliYunMessage;
use sms\BaiduYunMessage;
use sms\JiguangMessage;

class MessageFactory
{
    /**
     * @access public
     * @param string $type 商家 [阿里 Ali, 百度: Baidu, 极光: Jiguang]
     */
    public static function createMessage(string $type)
    {
        switch ($type) {
            case "Ali":
                return new AliYunMessage();
            case "Baidu":
                return new BaiduYunMessage();
            case "Jiguang":
                return new JiguangMessage();
            default:
                return null;
        }
    }
}

$business = 'Ali';
$message = MessageFactory::createMessage($business);
if($message){
    $message->send('您有新的短消息,请查收');
} else {
    echo '接口调用失败';
}